package icom.acm.action;

import icom.acm.action.Action;
import icom.acm.bean.T_JOB;
import icom.acm.manager.T_JobMgr;

public class JobAction extends Action{
	private T_JOB job;
	private String token;
	
	public String record() throws Exception {
		String token = (String)session.getAttribute("token");
		if (token==null){
			return "ERROR";
		} else if (!token.equals(this.token)){
			return "ERROR";
		}
		session.removeAttribute("token");
		T_JobMgr tjm = new T_JobMgr();
		tjm.insert(job);
		return "SUCCESS";
	}
	
	public String delete(){
		String token = (String)session.getAttribute("token");
		if (token==null){
			return "ERROR";
		} else if (!token.equals(this.token)){
			return "ERROR";
		}
		session.removeAttribute("token");
		T_JobMgr tjm = new T_JobMgr();
		tjm.delete(job.getJ_UID(), job.getJ_COMPANY());
		return "SUCCESS";
	}
	
	public String update(){
		String token = (String)session.getAttribute("token");
		if (token==null){
			return "ERROR";
		} else if (!token.equals(this.token)){
			return "ERROR";
		}
		session.removeAttribute("token");
		T_JobMgr tjm = new T_JobMgr();
		int id = tjm.update(job);
		if(id == -1){
			return "ERROR";
		}
		return "SUCCESS";
	}
	
	public T_JOB getJob() {
		return job;
	}
	public void setJob(T_JOB job) {
		this.job = job;
	}
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
}